package com.qf.ssm.controller;


import com.github.pagehelper.PageInfo;
import com.qf.ssm.qo.CarTypeQo;
import com.qf.ssm.result.ResponseResult;
import com.qf.ssm.service.CarTypeService;
import com.qf.ssm.vo.CarTypeVo;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(tags = "车型管理接口")
@RequestMapping("/car/type")
public class CarTypeController {

    @Autowired
    private CarTypeService carTypeService;

    @PostMapping("/insert")
    @ApiOperation("增加车型信息")
    @ApiImplicitParams({@ApiImplicitParam(name = "carTypeQo",value = "车型信息参数")})
    @ApiResponses({@ApiResponse(code = 2000, message = "成功", response = Integer.class), @ApiResponse(code = 4000, message = "未知错误)")})
    public ResponseResult<Integer> addCarType (@RequestBody CarTypeQo carTypeQo){
        return ResponseResult.success(carTypeService.saveCarType(carTypeQo));
    }
//
    @PostMapping("/list/{page}/{size}")
    @ApiOperation("分页查询和模糊查询车型信息")
    @ApiImplicitParams({@ApiImplicitParam(name = "carTypeQo",value = "车型信息参数")})
    @ApiResponses({@ApiResponse(code = 2000, message = "成功", response = CarTypeVo.class), @ApiResponse(code = 4000, message = "未知错误)")})
    public ResponseResult<PageInfo<CarTypeVo>> carTypeList(@ApiParam("页数")@PathVariable("page")Integer page,
                                                           @ApiParam("条数")@PathVariable("size")Integer size,
                                                           @RequestBody CarTypeQo carTypeQo){
        return  ResponseResult.success(carTypeService.carTypeList(page,size,carTypeQo));
    }


    @PutMapping("/update/{path}")
    @ApiOperation("修改车型信息")
    @ApiImplicitParams({@ApiImplicitParam(name = "carTypeQo",value = "车型信息参数")})
    @ApiResponses({@ApiResponse(code = 2000, message = "成功", response = Integer.class), @ApiResponse(code = 4000, message = "未知错误)")})
    public ResponseResult<Integer> updateCarType(@ApiParam("车型ID")@PathVariable("path")Integer tid,@RequestBody CarTypeQo carTypeQo){
        return ResponseResult.success(carTypeService.modifyCarType(tid,carTypeQo));
    }


    @DeleteMapping ("/delete/{path}")
    @ApiOperation("删除车型")
    @ApiResponses({@ApiResponse(code = 2000, message = "成功", response = Integer.class), @ApiResponse(code = 4000, message = "未知错误)")})
    public ResponseResult<Integer> deleteCarType(@ApiParam("车型ID")@PathVariable("path")Integer tid){
        return ResponseResult.success(carTypeService.removeCarType(tid));
    }

    @GetMapping("/{path}")
    @ApiOperation("根据ID查询车型")
    @ApiResponses({@ApiResponse(code = 2000, message = "成功", response = Integer.class), @ApiResponse(code = 4000, message = "未知错误)")})
    public ResponseResult<CarTypeVo> getCarType(@ApiParam("车型ID")@PathVariable("path") Integer tid){
        return ResponseResult.success(carTypeService.queryCarType(tid));
    }

}
